package com.project.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lyl
 * description:
 */
@Component
public class WebConfig implements WebMvcConfigurer {


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

//    /**
//     * 进行静态资源放行
//     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //将浏览器的请求地址引导至classpath的page文件夹下，注意，此classpath对应文件夹为target文件夹下生成的classes文件架
//        registry.addResourceHandler("/page/**").addResourceLocations("classpath:/page/");
//        registry.addResourceHandler("/img/**").addResourceLocations("file:d:/img2/");
//    }

    /**
     * 处理跨域问题
     *
     * @param registry
     */
    @SuppressWarnings("AlibabaAvoidCommentBehindStatement")
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  //跨域的URL
                .allowedHeaders("*")  //请求头
                .allowedMethods("*")  //请求方法
                .allowedOrigins("*");  //请求域名
    }
}